package com.hln.jingwushi.ui

import android.os.Bundle
import com.hln.jingwushi.MyBaseActivity
import com.hln.jingwushi.databinding.ActivitySystemSettingBinding
import com.hln.jingwushi.utils.DataCacheUtil
import com.gdsz.libbasic.utils.assist.getCurrentDataLong
import com.gdsz.libbasic.utils.assist.getWeek
import com.gdsz.libbasic.utils.assist.getYmd
import com.gdsz.libbasic.utils.assist.weekArray
import com.gdsz.libbasic.utils.view.throttleClick

class SystemSettingActivity : MyBaseActivity<ActivitySystemSettingBinding>() {

    override fun ActivitySystemSettingBinding.initBinding(savedInstanceState: Bundle?) {
        val currentDate = getCurrentDataLong()
        binding.tvDate.text = getYmd(currentDate)  + "   ${weekArray[getWeek(currentDate)]}"
        binding.tvName.text = DataCacheUtil.getName()
        binding.etAccessUrl.setText(DataCacheUtil.getAccessUrl())
        binding.etEquipmentUrl.setText(DataCacheUtil.getEquipmentUrl())
        binding.etAlcoholUrl.setText(DataCacheUtil.getAlcoholUrl())
        binding.etCarLocationUrl.setText(DataCacheUtil.getCarLocationUrl())
        binding.etName.setText(DataCacheUtil.getName())
        binding.etContactTel.setText(DataCacheUtil.getContactTel())
        binding.etContactPerson.setText(DataCacheUtil.getContactPerson())
        binding.etLawEnforcementUrl.setText(DataCacheUtil.getLawEnforcementUrl())
        binding.tvTip.text = "方舱运行状态正常，紧急联系电话：${binding.etContactTel.text}，紧急联系人：${binding.etContactPerson.text}"
    }

    override fun onClick() {
        super.onClick()
        binding.btnSave.throttleClick {
            DataCacheUtil.setAccessUrl(binding.etAccessUrl.text.toString())
            DataCacheUtil.setEquipmentUrl(binding.etEquipmentUrl.text.toString())
            DataCacheUtil.setAlcoholUrl(binding.etAlcoholUrl.text.toString())
            DataCacheUtil.setCarLocationUrl(binding.etCarLocationUrl.text.toString())
            DataCacheUtil.setName(binding.etName.text.toString())
            DataCacheUtil.setContactTel(binding.etContactTel.text.toString())
            DataCacheUtil.setContactPerson(binding.etContactPerson.text.toString())
            DataCacheUtil.setLawEnforcementUrl(binding.etLawEnforcementUrl.text.toString())
            finish()
        }
    }

    override fun notifyData(values: ShortArray) {
        runOnUiThread {
            binding.tvTemp.text = "温度 ${values[0]} ℃  湿度 ${values[1]} %"
        }

    }

}